var express = require('express');
var router = express.Router();
//var Excute = require('./lib/excute.js');
//var excute = new Excute(__dirname);
var async = require('async');
var fs = require('fs');
var useres = require('./useres.js');

var baseJson = {
  "status" : 1,
  "message": '',
  "value"  : ''
}



/* GET home page. */
router.post('/getRolePower',function ( req, res, next ){
  var roleId = req.body.roleId;
  var sql = 'SELECT * FROM role WHERE role.id = ? ;'+
            'SELECT * FROM power WHERE id IN ( SELECT power_id FROM role_power WHERE role_id = ? );'
  excute.query(sql,[roleId,roleId],function (result) {
    if(result){
      baseJson.status = 1;
      baseJson.message= '获取成功';
      baseJson.value  = result;
    }else{
      baseJson.status = 0;
      baseJson.message= '获取失败';
      baseJson.value  = '';
    }
    res.setHeader('content-type','text/plain;charset=utf-8');
    res.write(JSON.stringify(baseJson));
    res.end();
  });
});

router.get('/getAllUseres',function ( req, res, next ){
  var sql = '';
  sql += 'SELECT * FROM useres;';
  sql += 'SELECT * FROM dept;';
  sql += 'SELECT * FROM classes;';
  sql += 'SELECT * FROM major;';
  
  excute.query(sql,function (result) {
    if(result){
      baseJson.status = 1;
      baseJson.message= '获取成功';
      baseJson.value  = result;
    }else{
      baseJson.status = 0;
      baseJson.message= '获取失败';
      baseJson.value  = '';
    }
    res.setHeader('content-type','text/plain;charset=utf-8');
    res.write(JSON.stringify(baseJson));
    res.end();
  });
})

module.exports = router;
